package com.wkq.util.transformer

import android.view.View
import androidx.viewpager2.widget.ViewPager2

/**
 *
 *@Author: wkq
 *
 *@Time: 2025/7/30 10:04
 *
 *@Desc:
 */
class Flip3DTransformer : ViewPager2.PageTransformer {
    override fun transformPage(page: View, position: Float) {
        page.cameraDistance = 20000f

        when {
            position < -1 -> { // 页面在左侧屏幕外
                page.alpha = 0f
            }
            position <= 0 -> { // 从左向中间滑动
                page.alpha = 1f
                page.pivotX = page.width.toFloat()
                page.rotationY = 180 * position
            }
            position <= 1 -> { // 从右向中间滑动
                page.alpha = 1f
                page.pivotX = 0f
                page.rotationY = 180 * position
            }
            else -> { // 页面在右侧屏幕外
                page.alpha = 0f
            }
        }
    }
}
